#ifndef _TCP_H_
#define _TCP_H_

#include "unp.h"
namespace wakefieldq{

class CTcp
{
public:
	CTcp(int port);
	~CTcp();
private:
	int					servport;//define wellknow port number
	int 				listenfd;
	struct sockaddr_in 	cliaddr, servaddr;
	socklen_t 				clilen, servlen;
	/* data */
public:
	/**
	* start a socket with steps below:
	* 1. socket(AF_INET, SOCK_STREAM, 0)
	* 2. bind(listenfd, (SA* )&servaddr, sizeof(servaddr))
	* 3. listen(listenfd, LISTENQ);
	* RETURN:
	* 	listenfd
	*/
	int open_listen();
	/**
	* get a connection from a client
	*/
	int receive();
	/**
	* start a connection to a server
	**/
	int connectto(char* str_ipaddr);

	int get_cliaddr(struct sockaddr_in* cliaddr);

	int get_servaddr(struct sockaddr_in* servaddr);

	void Close(int connfd);

	char* sock_ntop(const struct sockaddr* sa, socklen_t salen, char* buf);
};

}
#endif
